//
//  SYNewDynamicViewController.m
//  ChatDemo-UI2.0
//
//  Created by zz on 16/11/28.
//  Copyright © 2016年 zz. All rights reserved.
//

static NSString * dynamicIdentifier = @"FriendDynamic";


static NSMutableArray *itemDataArr;

static int keyBoardCount;  //用于记录键盘出现的次数

#import "FLAdView.h"
#import "ImageDisplayView.h"
//#import "UIImageView+AFNetworking.h"

#import "SDPhotoBrowser.h"

#import "DetailDynViewController.h"
#import "FriendSysTableViewCell.h"
#import "WebViewController.h"
#import "FriendSysNoticeTableViewCell.h"


#import "ReplayTableCell.h"


#import <AVFoundation/AVFoundation.h>
#import "SVProgressHUD.h"

#import "CustomAlert.h"
#import "AssignHomeWorkViewController.h"

#import "XZHeaderImageView.h"

#import "SendDynamicViewController.h"
#import "DropDownMenu2.h"
@interface FriendDynamicViewCell () <SDPhotoBrowserDelegate,UIGestureRecognizerDelegate,DropDownMenu2Delegate>



@end

@implementation FriendDynamicViewCell

@synthesize nameLabel;
@synthesize contentLabel;
@synthesize timeLabel;
@synthesize headImage;
@synthesize clickBtn;
@synthesize btnArray;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    // ignore the style argument and force the creation with style UITableViewCellStyleSubtitle
    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    
    itemDataArr = [NSMutableArray array];
    
    //初始化可变数组
    _imageArr = [NSMutableArray array];
    
    
    if (self) {
        
        //昵称
        nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(69, 15, SCREENWIDTH - 69 - 20, 15)];
        nameLabel.font = [UIFont systemFontOfSize:15];
        nameLabel.textColor = [UIColor colorWithHexString:@"1ebfff"];
        nameLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:nameLabel];
        
        //内容
        contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(nameLabel.frame.origin.x, nameLabel.frame.origin.y + nameLabel.frame.size.height + 8, nameLabel.frame.size.width, 0)];
        contentLabel.textColor = [UIColor colorWithHexString:@"#3b3b3b"];
        contentLabel.font = [UIFont systemFontOfSize:14];
        contentLabel.numberOfLines = 0;
        [self addSubview:contentLabel];
        
        //时间
        timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(69, self.frame.size.height - 8,nameLabel.frame.size.width,15)];
        timeLabel.font = [UIFont systemFontOfSize:14];
        timeLabel.textAlignment = NSTextAlignmentLeft;
        timeLabel.textColor = [UIColor colorWithHexString:@"#979797"];
        
        [self addSubview:timeLabel];
        
        //删除按钮
        _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _deleteBtn.frame = CGRectMake(CGRectGetMaxX(timeLabel.frame) + 5, self.frame.size.height - 8, 50, 20);
        [_deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
        [_deleteBtn setTitleColor:[UIColor colorWithHexString:@"#1ebfff"] forState:UIControlStateNormal];
        
        _deleteBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        _deleteBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
        _deleteBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [self.contentView addSubview:_deleteBtn];
        
        //交互按钮
        clickBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        [clickBtn setImage:[UIImage imageNamed:@"tanchu_nor"] forState:UIControlStateNormal];

        clickBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
        clickBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [self addSubview:clickBtn];
        
        
        //头像
        headImage = [[XZHeaderImageView alloc] initWithFrame:CGRectMake(15, 15, 42, 42)];
        headImage.contentMode = UIViewContentModeScaleAspectFill;
        headImage.clipsToBounds = YES;
        headImage.layer.cornerRadius = 21;
        [self addSubview:headImage];
        
        _likeCommentView = [[replayView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH - 89, 10)];
        _likeCommentView.layer.cornerRadius = 3;
        [self.contentView addSubview:_likeCommentView];
    }
    
    
    return self;
}


-(CGRect)upDateCellWithDic:(NSDictionary *)dict{
    
    dict=[ConfirmationNsnull nullDic:dict];
    NSString *userid = [[dict objectForKey:@"userid"] stringValue];
    
    if ([userid isEqualToString:USERID]) { //自己发布的动态可以删除
        self.deleteBtn.hidden = NO;
    }else{
        self.deleteBtn.hidden = YES;
    }
    
//    NSString *nick=[dict objectForKey:@"groupnickname"];
//    if (nick.length==0) {
//        nick=[dict objectForKey:@"username"];
//    }
//    
//    if ([nick hasSuffix:@"老师"]) {
//        
//       nick = [nick stringByReplacingOccurrencesOfString:@"老师" withString:@""];
//    }
    
    NSString *nick=[dict objectForKey:@"username"];
    
    //昵称
    self.nameLabel.text =nick ;
    
    //内容
    self.contentLabel.text = [dict objectForKey:@"scontent"];
    
    //图片数组
    NSString * fileidsStr = [dict objectForKey:@"fileid"];
    NSArray *fileids;
    
    if (fileidsStr.length != 0) {
        
        fileids = [fileidsStr componentsSeparatedByString:@","];
    }
    
    
    [self.contentLabel setFrame:CGRectMake(self.contentLabel.frame.origin.x, CGRectGetMaxY(self.nameLabel.frame) + 6, self.contentLabel.frame.size.width, [self resizeContenLabelHeightWithSting:[dict objectForKey:@"scontent"]])];
    _images = nil;
    _images = fileids;
    
    for (UIView *subview in _bgView.subviews) {
        [subview removeFromSuperview];
    }
    
    _bgView = nil;
    [_imageArr removeAllObjects];
    
    if (fileids.count != 0) {  //有图片
        
        _bgView = [[UIView alloc] init];
        [self.contentView addSubview:_bgView];
        
        
        NSInteger line = 0;
        if ([fileids count]%3 == 0) {
            line = [fileids count]/3;
        }else
        {
            line = [fileids count]/3 + 1;
        }
        
        _bgView.frame = CGRectMake(0, CGRectGetMaxY(self.contentLabel.frame)+9, SCREENWIDTH,(5 + 79) * line - 5);
        _bgView.clipsToBounds = YES;
        _bgView.userInteractionEnabled = YES;
        
    }
    
    CGRect rect;
    
    for (NSInteger index = 0 ;index < [fileids count] ; index ++) {
        
        NSString *iamgename = [fileids objectAtIndex:index];
        rect = CGRectMake(69 + (79 + 5) * (index %3),(79 + 5) * (index / 3), 79, 79);
        
        UIImageView * imageView = [[UIImageView alloc] initWithFrame:rect];
        
        imageView.userInteractionEnabled = YES;
        
        NSString * imageString = [NSString stringWithFormat:@"%@%@&s=%d",IMAGEHOSTURL,iamgename,ImageWidht];
        
        [imageView sd_setImageWithURL:[NSURL URLWithString:imageString] placeholderImage:[UIImage imageNamed:@"emptyPic"]];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        tap.numberOfTapsRequired = 1;
        tap.numberOfTouchesRequired = 1;
        
        [imageView addGestureRecognizer:tap];
        imageView.tag = index;
        
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.clipsToBounds = YES;
        
        [_imageArr addObject:imageView];
        
        [_bgView addSubview:imageView];
        
    }
    
    NSString * timeStr = [dict objectForKey:@"jointime"];
    
    timeStr = [Utils getDataStringWithoutSecondString:timeStr];
    
    self.timeLabel.text = timeStr;

    CGFloat timeLabelW = [self.timeLabel sizeThatFits:CGSizeMake(100, 20)].width;
    
    if (fileids.count != 0) {
        
//        rect.origin.y += CGRectGetMaxY(self.contentLabel.frame) + 7;
        
        [self.timeLabel setFrame:CGRectMake(nameLabel.frame.origin.x, CGRectGetMaxY(self.bgView.frame) + 15, timeLabelW, 14)];
        [self.deleteBtn setFrame:CGRectMake(CGRectGetMaxX(self.timeLabel.frame)+15, self.timeLabel.frame.origin.y - 1, 50, 20)];
        [clickBtn setFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-20 - 60, self.timeLabel.frame.origin.y,60, 30)];
    }else{
        
        [self.timeLabel setFrame:CGRectMake(nameLabel.frame.origin.x, CGRectGetMaxY(self.contentLabel.frame)+15, timeLabelW, 14)];
        [self.deleteBtn setFrame:CGRectMake(CGRectGetMaxX(self.timeLabel.frame) + 15, self.timeLabel.frame.origin.y - 1, 50, 20)];
        [clickBtn setFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-20 - 60, self.timeLabel.frame.origin.y, 60,30)];
    }
    
    
    DFBaseLineItem *item = [DFBaseLineItem dictionaryWithDic:dict];
    
    [itemDataArr addObject:item];
    
    [self updateWithItem:item];
    
    return rect;
}


-(void)updateWithItem:(DFBaseLineItem *)item{
    
    CGFloat x,y,w,h;
    
    self.item = item;
    //点赞和评论
    if (self.item.praiseuser.count ==0 && self.item.replylist.count == 0) {
        
        _likeCommentView.hidden = YES;
    }else{
        _likeCommentView.hidden = NO;
        
        x = CGRectGetMinX(self.timeLabel.frame);
        y = CGRectGetMaxY(self.timeLabel.frame) + 5;
        w = _likeCommentView.frame.size.width;
        h = [replayView getHeight:self.item maxWidth:SCREENWIDTH - 89];
        _likeCommentView.frame = CGRectMake(x, y, w, h);
        [_likeCommentView updateWithItem:self.item];
    }
}


-(void)tapAction:(UIGestureRecognizer *)gesture{
    
    SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];
    browser.sourceImagesContainerView = _bgView;
    browser.imageCount = _images.count;
    
    browser.currentImageIndex = (int)gesture.view.tag;
    browser.delegate = self;
    [browser show];
}

//-(UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index{
//
//    UIImageView *imageView = _imageArr[index];
//    return imageView.image;
//}
//
//-(NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index{
//
//    NSString *urlStr = _images[index];
//
//    //if (![urlStr hasPrefix:@"http"]) {
//        //urlStr = [NSString stringWithFormat:@"%@%@",REQUESTIMAGEURL,urlStr];
//    //}
//
//    return [NSURL URLWithString:urlStr];
//}

-(UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index flag:(NSString *)flagStr{
    
    NSString *str = _images[index];
    NSString *logoStr;
    if ([flagStr isEqualToString:@"1"]) {
        logoStr = [PICPERFIXURL stringByAppendingString:str];
    }else
    {
        logoStr = [PICPERFIXURL stringByAppendingString:str];
        logoStr=[NSString stringWithFormat:@"%@&s=%d",logoStr,ImageWidht];
    }
    
    UIImageView *imageView = [[UIImageView alloc] init];
    
    __block UIImage *_image;
    [imageView sd_setImageWithURL:[NSURL URLWithString:logoStr] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        _image = image;
    }];
    return _image;
}

- (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index flag:(NSString *)flagStr{
    
    NSString *str = _images[index];
    NSString *logoStr;
    if ([flagStr isEqualToString:@"1"]) {
        logoStr = [PICPERFIXURL stringByAppendingString:str];
    }else
    {
        logoStr = [PICPERFIXURL stringByAppendingString:str];
        logoStr=[NSString stringWithFormat:@"%@&s=%d",logoStr,ImageWidht];
    }
    
    
    NSURL *url = [NSURL URLWithString:logoStr];
    return url;
}

#pragma mark -- other
- (CGFloat)resizeContenLabelHeightWithSting:(NSString *)text
{
    if (text.length == 0) {
        return 0;
    }
    UIFont *font = [UIFont systemFontOfSize:14];
    
    NSStringDrawingOptions opts = NSStringDrawingUsesLineFragmentOrigin;
    
    //NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    //[style setLineBreakMode:NSLineBreakByCharWrapping];
    
    NSDictionary *attributes = @{ NSFontAttributeName : font};
    
    CGSize maxSize = CGSizeMake(nameLabel.frame.size.width, 6000);
    CGSize size = [text boundingRectWithSize:maxSize
                                     options:opts
                                  attributes:attributes
                                     context:nil].size;
    return size.height;
}

@end

#pragma mark -分界线============================================


#import "SYNewDynamicViewController.h"
#import "DyCollectionViewCell.h"
#import "DyRightCollectionViewCell.h"
#import "photoListModel.h"
#import "ClassPhotoViewController.h"
#import "SYClassPhotoCell.h"
#import "DropTable.h"
#import "ShouCangViewController.h"

@interface SYNewDynamicViewController ()<FLAdViewDelegate,UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate
,yunDouAlertDelegate,DynamicViewDelegate,UIAlertViewDelegate,UIGestureRecognizerDelegate,LikeCommentViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,reloadDataDelegate,DropTableDelgate>{
    
    BOOL canFlipOver;
    BOOL photoFlipOver;
    NSInteger pageno;
    NSMutableArray *dataArray;
    
    NSMutableArray *photosDataArray;
    
    //背景图
    UIImageView *bgImageView;
    
    //背景图片的url
    NSString *bgImageUrl;
    
    //头像
    XZHeaderImageView *headImageView;
    
    //头像的url
    NSString *headUrl;
    
    //选择的图片
    UIImage *chooseImage;
    
    //昵称
    NSString *nickName;
    
    NSString *nickName2;
    
    //logetype
    int hLogoType;
    
    BOOL state;  //状态
    
    NSString *classid; //班级id
    
    AppDelegate * delegate;
    
    SYAccount *accountDic;
    
    EmptyStateView *emptyView;//空状态
    EmptyStateView *noWifiView;//无网络状态
    EmptyStateView *noPhotoWifiView;//无网络状态
    
    int markLabel;
    
    UIView *navTitleView;//自定义nav titleView
    
    UICollectionView * collect;
    
    int count;
    
    int pageNum;
    
    int pageNo;
    
    int photoPageNum;
    
    UIBarButtonItem *right;
}

//表情页面
@property(nonatomic,strong) UIButton *emotionButton;
@property(nonatomic,strong)UITextView *textView;
@property(nonatomic,strong) UIView *bottomView;

//用于view的移动，使评论框落在cell下面
@property (nonatomic,assign)float replyViewDraw;

//键盘的弹出状态
@property(nonatomic,assign) BOOL keyboardState;

@property (nonatomic,strong) UITableView *tableView;

@property (nonatomic,strong) UITableView *classPhontoTableView;

@property (nonatomic, strong) UISegmentedControl *segment;



@end

@implementation SYNewDynamicViewController
@synthesize backView;

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [self configureKeyboardNoti];
    
}

-(void)viewWillDisappear:(BOOL)animated{
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    
    [self.bottomView removeFromSuperview];
    //    [nodataImage removeFromSuperview];
    [super viewWillDisappear:animated];
    
}

- (UITableView *)classPhontoTableView
{
    if (_classPhontoTableView == nil) {
        
        _classPhontoTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight, SCREENWIDTH, SCREENHEIGH-SafeAreaTopHeight) style:UITableViewStylePlain];
        _classPhontoTableView.delegate = self;
        _classPhontoTableView.dataSource = self;
        _classPhontoTableView.showsVerticalScrollIndicator = NO;
        _classPhontoTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    
    return _classPhontoTableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configureNav];
    
    accountDic=[SYAccountTool ShareAccount].account;
    lasttype = [NSString stringWithFormat:@"%d",accountDic.lasttype];
    if ([self->bgImageUrl isEqualToString:@"0"]) {
   
        bgImageUrl = @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1458264274&di=75597c9973c5572952d28f9f880defd2&src=http://file25.mafengwo.net/M00/00/84/wKgB4lYvUmeAWxYLAAu-KKvEhO037.jpeg";
    }else
    {
       bgImageUrl=[NSString stringWithFormat:@"%@%d",PICPERFIXURL,accountDic.basepic];
    }
   
    delegate = (AppDelegate *)CONSTAPPDELEGATE;
    
    count = 0;
    photosDataArray = [NSMutableArray array];
    
    [self loadTableView];
}

- (void)loadTableView
{
    if ([lasttype isEqualToString:@"1"]) {
        
        [emptyView hideEmptyImage];
        
        [self requestDataForTableview];
    }else
    {
        [emptyView hideEmptyImage];
        [self requestSouceData];
        //[self  loadParentStudentList];  //判断有没有关联孩子
    }
    
//    [self getUserInfoWithUserid:USERID];
    _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREENHEIGH, SCREENWIDTH, 50)];
    _bottomView.backgroundColor = RGBACOLOR(247, 247, 247, 1);
    
    _textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 10, SCREENWIDTH-40, 30)];
    
    _textView.textColor = [UIColor blackColor];
    
    _textView.layer.masksToBounds = YES;
    //_textView.layer.borderWidth = 0.6;
    
    _textView.returnKeyType = UIReturnKeySend;
    _textView.font = [UIFont systemFontOfSize:14];
    _textView.delegate = self;
    _textView.scrollEnabled = YES;
    //[_textView becomeFirstResponder];
    
    //显示右侧的指示
    _textView.showsVerticalScrollIndicator = YES;
    //这句话可以让textview输入中文的时候不在上下跳动
    _textView.layoutManager.allowsNonContiguousLayout = NO;
    [_bottomView addSubview:_textView];
    
    //[self configureKeyboardNoti];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, SafeAreaTopHeight, VIEW_WIDTH, VIEW_HEIGHT - SafeAreaTopHeight) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.showsVerticalScrollIndicator = NO;
    
    //设置headerview与tableview
    
    int lastTyper = [SYAccountTool ShareAccount].account.lasttype;
    
    self.tableView.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
        
        if (lastTyper == 1) {
            
            [self requestDataForTableview];
            
        }else if (lastTyper == 2){
            
            [self requestSouceData];
        }
        
    }];
    
    self.tableView.mj_footer = [MJRefreshFooter footerWithRefreshingBlock:^{
        
        if (lastTyper == 1) {
            
            [self requestMoreDataForTableview];
            
        }else if (lastTyper == 2){
            
            [self requestMoreSouceData];
        }
        
    }];
    
    [self.view addSubview:self.tableView];
    
    noWifiView = [[EmptyStateView alloc] initNoWifiWithFrame:CGRectMake(0, (SCREENHEIGH-64-175)/2, SCREENWIDTH, 175) andBackImage:@"noWifi" andBottomStr:@"网络出错啦,点击重新加载"];
    noWifiView.userInteractionEnabled= YES;
    noWifiView.delegate = self;
    [self.view addSubview:noWifiView];
    
    noPhotoWifiView = [[EmptyStateView alloc] initNoWifiWithFrame:CGRectMake(0, (SCREENHEIGH-64-175)/2, SCREENWIDTH, 175) andBackImage:@"noWifi" andBottomStr:@"网络出错啦,点击重新加载"];
    noPhotoWifiView.userInteractionEnabled= YES;
    noPhotoWifiView.delegate = self;
    [self.view addSubview:noPhotoWifiView];
    
    
    dataArray = [[NSMutableArray alloc] initWithCapacity:0];
    
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
    [self.tableView setTableFooterView:v];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.separatorColor = [UIColor colorWithHexString:@"#dedede"];
    
    emptyView = [[EmptyStateView alloc] initWithFrame:CGRectMake((SCREENWIDTH-120)/2, (SCREENHEIGH-110+210)/2-70, 120, 110) andBackImage:@"dynamic_empty" andBottomStr:@"暂无班级动态"];
    [self.tableView addSubview:emptyView];
    
    canFlipOver = NO;
    pageno = 1;
    
    _keyboardState = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resignTap:)];
    [self.view addGestureRecognizer:tap];
    tap.delegate = self;
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    keyBoardCount = 1;
}

-(void)configureNav{
    
    self.title = @"班级动态";
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor=[UIColor whiteColor];
    UIBarButtonItem *left = [[UIBarButtonItem alloc] initWithImage:[UIImage imageWithOriginalName:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem = left;
   
   self.navBar.centerView.hidden = NO;
//    navTitleView = [[UIView alloc]initWithFrame:CGRectMake((SCREENWIDTH-194)/2, 6, 194, 26)];
//    navTitleView.userInteractionEnabled = YES;
//    navTitleView.backgroundColor = [UIColor clearColor];
   
    self.segment = [[UISegmentedControl alloc] initWithItems:@[@"班级动态",@"班级相册"]];
    [self.segment addTarget:self action:@selector(segmentChange:) forControlEvents:(UIControlEventValueChanged)];
    self.segment.size = CGSizeMake(194, 26);
    self.segment.center = CGPointMake(97,13);
    self.segment.selectedSegmentIndex = 0;
//    self.segment.tintColor = RGBCOLOR(57, 173, 255);
    self.segment.tintColor = [UIColor colorWithHexString:@"#1ebfff"];
    
    
    UIFont *font = [UIFont systemFontOfSize:14.0f];
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
                                                           forKey:UITextAttributeFont];
    [self.segment setTitleTextAttributes:attributes
                                forState:UIControlStateNormal];
    
    
    [ self.navBar.centerView addSubview:self.segment];
//    
//    self.navBar.centerView = navTitleView;

   self.navBar.rightImg.hidden = NO;
   self.navBar.rightButton.hidden = NO;
   self.navBar.rightImg.image = [UIImage imageWithOriginalName:@"ios_more_"];
   [self.navBar.rightButton addTarget:self action:@selector(dis:) forControlEvents:UIControlEventTouchUpInside];
    
    
}

-(void)segmentChange:(UISegmentedControl *)segment {
    
    if (segment.selectedSegmentIndex == 0) {

        [noPhotoWifiView hideEmptyImage];
        
        self.classPhontoTableView.hidden = YES;
        
        
        self.tableView.hidden = NO;
        
        if (self.navBar.rightButton.hidden == YES &&self.navBar.rightImg.hidden==YES) {
           
           self.navBar.rightButton.hidden = NO;
           self.navBar.rightImg.hidden =NO;
        }
       
        if ([lasttype isEqualToString:@"1"]) {
            
            [self requestDataForTableview];
        }else
        {
            [self requestSouceData];

        }

    }else
    {
        [noWifiView hideEmptyImage];
        
       self.navBar.rightButton.hidden = YES;
       self.navBar.rightImg.hidden =YES;
        
        self.tableView.hidden = YES;
        
        if (count==0) {
            
            [self loadClassTableView];
            
            count ++;
            
        }else
        {
            self.classPhontoTableView.hidden = NO;
            
            if ([lasttype isEqualToString:@"1"]) {
                
                [self requestTearchPhotosData];
            }else
            {
                [self requestParPhotosData];
                
            }
        }
        
        
    }
    
}

//班级相册 老师端

- (void)requestTearchPhotosData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_dynamicphoto_list" forKey:@"method"];
    [dict setObject:@"10" forKey:@"pagesize"];
    [dict setObject:USERID forKey:@"userid"];
    [dict setObject:@"1" forKey:@"pageno"];
   
   if ([SYAccountTool ShareAccount].account.schoolManage > 0) {
      
      NSString * scid = [SYAccountTool ShareAccount].account.scid;
      
      if (scid != nil) {
         
         [dict setObject: scid forKey:@"scid"];
      }
      
   }else{
      
      [dict setObject:@"0" forKey:@"scid"];
   }
   
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        [self->photosDataArray removeAllObjects];
        
        NSDictionary *dict = (NSDictionary *)resposeJson;
        NSArray * array = [dict objectForKey:@"re_data"];
        NSLog(@"re_data = %@",array);
        if (array.count == 0) {
            
            [self->emptyView showEmptyImage];
            [self->_classPhontoTableView reloadData];
            [self->_classPhontoTableView.mj_header endRefreshing];
            return ;
        }else if(array.count == 10)
        {
            self->photoFlipOver = YES;
            
        }else
        {
            self->photoFlipOver = NO;
        }
        [self->emptyView hideEmptyImage];
        
        self->photoPageNum = 2;
        
        for (NSDictionary *dic in array) {
            
            photoListModel *model = [photoListModel mj_objectWithKeyValues:dic];
            
            [self->photosDataArray addObject:model];
        }

        
        [self->_classPhontoTableView reloadData];
        [self->_classPhontoTableView.mj_header endRefreshing];

    } failure:^(NSInteger recode, NSError * error){
        
        if (error.code == -1009) {
            self->markLabel = 2;
            self->_classPhontoTableView.hidden = YES;
            [self->noPhotoWifiView showEmptyImage];
        }
    }];

}
- (void)requestTearchMorePhotosData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_dynamicphoto_list" forKey:@"method"];
    [dict setObject:@"10" forKey:@"pagesize"];
    [dict setObject:USERID forKey:@"userid"];
    [dict setObject:@(photoPageNum) forKey:@"pageno"];
   if ([SYAccountTool ShareAccount].account.schoolManage > 0) {
      
      NSString * scid = [SYAccountTool ShareAccount].account.scid;
      
      if (scid != nil) {
         
         [dict setObject: scid forKey:@"scid"];
      }
      
   }else{
      
      [dict setObject:@"0" forKey:@"scid"];
   }
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson)
    {
        
        NSDictionary *dict = (NSDictionary *)resposeJson;
        NSArray * array = [dict objectForKey:@"re_data"];
        
        if (array.count == 10) {
            
            self->photoPageNum ++;
            
            self->photoFlipOver = YES;
        }else
        {
            self->photoFlipOver = NO;
            
        }
        
        for (NSDictionary *dic in array) {
            
            photoListModel *model = [photoListModel mj_objectWithKeyValues:dic];
            
            [self->photosDataArray addObject:model];
        }
        
        
        [self->_classPhontoTableView reloadData];
        [self->_classPhontoTableView.mj_footer endRefreshing];

    } failure:^(NSInteger recode, NSError * error){
        
        if (error.code == -1009) {
            self->markLabel = 2;
            self->_classPhontoTableView.hidden = YES;
            [self->noPhotoWifiView showEmptyImage];
        }
    }];
    
}
- (void)requestParPhotosData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_dynamicphoto_liststudent" forKey:@"method"];
    [dict setObject:@"10" forKey:@"pagesize"];
    [dict setObject:USERID forKey:@"userid"];
    [dict setObject:@"1" forKey:@"pageno"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        [self->photosDataArray removeAllObjects];
        
        NSDictionary *dict = (NSDictionary *)resposeJson;
        NSArray * array = [dict objectForKey:@"re_data"];
        
        NSLog(@"111111= %@",dict);
        if (array.count == 0) {
            
            [self->emptyView showEmptyImage];
            [self->_classPhontoTableView reloadData];
            [self->_classPhontoTableView.mj_header endRefreshing];
            
            return ;
        }else if(array.count == 10)
        {
            self->photoFlipOver = YES;
            
        }else
        {
            self->photoFlipOver = NO;
        }
        [self->emptyView hideEmptyImage];
        
        self->photoPageNum = 2;
        
        for (NSDictionary *dic in array) {
            
            photoListModel *model = [photoListModel mj_objectWithKeyValues:dic];
            
            [self->photosDataArray addObject:model];
        }
        NSLog(@"photosDataArray = %@",self->photosDataArray);
        
        [self->_classPhontoTableView reloadData];
        [self->_classPhontoTableView.mj_header endRefreshing];
        
    } failure:^(NSInteger recode, NSError * error){
        
        if (error.code == -1009) {
            self->markLabel = 2;
            self->_classPhontoTableView.hidden = YES;
            [self->noPhotoWifiView showEmptyImage];
        }
    }];
    
}
- (void)requestParMorePhotosData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_dynamicphoto_liststudent" forKey:@"method"];
    [dict setObject:@"10" forKey:@"pagesize"];
    [dict setObject:USERID forKey:@"userid"];
    [dict setObject:@(photoPageNum) forKey:@"pageno"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson)
     {
         
         NSDictionary *dict = (NSDictionary *)resposeJson;
         NSArray * array = [dict objectForKey:@"re_data"];
         
         if (array.count == 10) {
             
             self->photoPageNum ++;
             
             self->photoFlipOver = YES;
         }else
         {
             self->photoFlipOver = NO;
             
         }
         
         for (NSDictionary *dic in array) {
             
             photoListModel *model = [photoListModel mj_objectWithKeyValues:dic];
             
             [self->photosDataArray addObject:model];
         }
         
         
         [self->_classPhontoTableView reloadData];
         
         [self->_classPhontoTableView.mj_footer endRefreshing];
         
     } failure:^(NSInteger recode, NSError * error){
         
         if (error.code == -1009) {
             self->markLabel = 2;
             self->_classPhontoTableView.hidden = YES;
             [self->noPhotoWifiView showEmptyImage];
         }
     }];
    
}

- (void)loadClassTableView
{
    if ([lasttype isEqualToString:@"1"]) {
        
        [self requestTearchPhotosData];
        
    }else
    {
        [self requestParPhotosData];
    }
    
    
//    //创建一个layout布局类
//    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
//    //设置布局方向为垂直流布局
//    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
//    //设置每个item的大小为100*100
//    layout.itemSize = CGSizeMake(SCREENWIDTH/2 , 186);
//    
//    //创建collectionView 通过一个布局策略layout来创建
//    collect = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGH-64-20) collectionViewLayout:layout];
//    
//    collect.backgroundColor = [UIColor whiteColor];
//    //代理设置
//    collect.delegate=self;
//    collect.dataSource=self;
//    collect.hidden = NO;
//    [collect setShowsVerticalScrollIndicator:NO];
//    //注册item类型 这里使用系统的类型
//    [collect registerClass:[DyCollectionViewCell class] forCellWithReuseIdentifier:@"cellid"];
//    
//    [collect registerClass:[DyRightCollectionViewCell class] forCellWithReuseIdentifier:@"cellid2"];
//    
//    collect.mj_header = [MJRefreshHeader headerWithRefreshingBlock:^{
//        
//        if ([self->lasttype isEqualToString:@"1"]) {
//            
//            [self requestTearchPhotosData];
//        }else
//        {
//            [self requestParPhotosData];
//        }
//        
//        
//    }];
//    
//    collect.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
//        
//        if ([self->lasttype isEqualToString:@"1"]) {
//            
//            [self requestTearchMorePhotosData];
//            
//        }else
//        {
//            [self requestParMorePhotosData];
//        }
//        
//    }];
//
//    
//    [self.view addSubview:collect];
    self.classPhontoTableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        if ([self->lasttype isEqualToString:@"1"]) {
            
            [self requestTearchPhotosData];
        }else
        {
            [self requestParPhotosData];
        }
        
    }];
    
    self.classPhontoTableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
        if ([self->lasttype isEqualToString:@"1"]) {
            
            [self requestTearchMorePhotosData];
            
        }else
        {
            [self requestParMorePhotosData];
        }
        
    }];
    
    [self.view addSubview:self.classPhontoTableView];
    
    

}

////定义展示的Section的个数
//-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
//{
//    return 1;
//}
////定义展示的UICollectionViewCell的个数
//-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
//{
//    return [photosDataArray count];
//}
//
////定义每个UICollectionView 的大小
//- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
//{
//    return CGSizeMake(SCREENWIDTH/2-10, 186);
//}
//
////定义每个UICollectionView 的 margin
//-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
//{
//    return UIEdgeInsetsMake(5, 5, 5, 5);
//}
//
////返回这个UICollectionView是否可以被选择
//-(BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
//{
//    return YES;
//}
//
//- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
//{
//    photoListModel *model = [photosDataArray objectAtIndex:indexPath.row];
//    
//    ClassPhotoViewController *VC = [[ClassPhotoViewController alloc]init];
//    VC.className = model.classname;
//    VC.classid = model.classid;
//    [self.navigationController pushViewController:VC animated:YES];
//}
////这是正确的方法
//-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
//    
//    photoListModel *model = [photosDataArray objectAtIndex:indexPath.row];
//    
//    if (indexPath.row%2==0) {
//        
//        DyCollectionViewCell *cell = (DyCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellid" forIndexPath:indexPath];
//        [cell setDataForCellWith:model];
//        return cell;
//        
//    }else
//    {
//        DyRightCollectionViewCell * cell = (DyRightCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cellid2" forIndexPath:indexPath];
//        [cell setDataForCellWith:model];
//        return cell;
//        
//    }
//    
//}
//- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
//{
//    
//    if (photoFlipOver == NO) {
//        
//        collect.mj_footer = nil;
//        
//    }else if (photoFlipOver == YES){
//        
//        
//        collect.mj_footer = [MJRefreshAutoFooter footerWithRefreshingBlock:^{
//            
//            if ([self->lasttype isEqualToString:@"1"]) {
//                
//                [self requestTearchMorePhotosData];
//                
//            }else
//            {
//                [self requestParMorePhotosData];
//            }
//            
//        }];
//        
//
//    }
//}
-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)resignTap:(UIGestureRecognizer *)tap{
    
    
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    
    if ([_textView isFirstResponder]) {
        
        [_textView resignFirstResponder];
        
    }
    
    return NO;
}



//老师角色 动态列表
- (void)requestDataForTableview
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_dynamic_list" forKey:@"method"];
    [dict setObject:@"20" forKey:@"pagesize"];
    [dict setObject:USERID forKey:@"userid"];
    [dict setObject:@"1" forKey:@"pageno"];
    [dict setObject:@"1" forKey:@"type"];
    [dict setObject:@"0" forKey:@"studentid"];
   
   if ([SYAccountTool ShareAccount].account.schoolManage > 0) {
      
      NSString * scid = [SYAccountTool ShareAccount].account.scid;
      
      if (scid != nil) {
         
          [dict setObject: scid forKey:@"scid"];
      }
     
      
   }else{
      
      [dict setObject:@"0" forKey:@"scid"];
   }
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        [self->dataArray removeAllObjects];
        
        NSDictionary *dict = (NSDictionary *)resposeJson;
        NSArray * array = [dict objectForKey:@"re_data"];
        
        if (array.count == 0) {
            
            [self->emptyView showEmptyImage];
            [self->_tableView reloadData];
            [self->_tableView.mj_header endRefreshing];
            self->_tableView.tableFooterView = [[UIView alloc]init];
            
            return ;
        }else if(array.count == 20)
        {
            self->canFlipOver = YES;
            
        }else
        {
            self->canFlipOver = NO;
            
        }
        [self->emptyView hideEmptyImage];
        
        self->pageNum = 2;
        
        [self->dataArray addObjectsFromArray:array];
        
        [self.tableView reloadData];
        [self.tableView.mj_header endRefreshing];
        self->delegate.isChangeRole=@"no";
    } failure:^(NSInteger recode, NSError * error){
        
        if (error.code == -1009) {
            self->markLabel = 1;
            self.tableView.hidden = YES;
            [self ->noWifiView showEmptyImage];
        }
        
    }];
}


//老师角色 动态列表
- (void)requestMoreDataForTableview
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_dynamic_list" forKey:@"method"];
    [dict setObject:@"20" forKey:@"pagesize"];
    [dict setObject:USERID forKey:@"userid"];
    [dict setObject:@(pageNum) forKey:@"pageno"];
    [dict setObject:@"1" forKey:@"type"];
    [dict setObject:@"0" forKey:@"studentid"];
   
   if ([SYAccountTool ShareAccount].account.schoolManage > 0) {
      
      NSString * scid = [SYAccountTool ShareAccount].account.scid;
      
      if (scid != nil) {
         
         [dict setObject: scid forKey:@"scid"];
      }
      
   }else{
      
      [dict setObject:@"0" forKey:@"scid"];
   }
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        NSDictionary *dict = (NSDictionary *)resposeJson;
        NSArray * array = [dict objectForKey:@"re_data"];
        
        if (array.count == 20) {
            
            self->pageNum ++;
            
            self->canFlipOver = YES;
        }else
        {
            self->canFlipOver = NO;
        }
        
        [self->dataArray addObjectsFromArray:array];
        [self.tableView reloadData];
        [self.tableView.mj_footer endRefreshing];
        self->delegate.isChangeRole=@"no";
        
    } failure:^(NSInteger recode, NSError * error){
        
        if (error.code == -1009) {
            self->markLabel = 1;
            self.tableView.hidden = YES;
            [self ->noWifiView showEmptyImage];
        }
    }];
}


//家长角色动态列表
-(void)requestSouceData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_dynamic_liststudent" forKey:@"method"];
    [dict setObject:@"20" forKey:@"pagesize"];
    [dict setObject:USERID forKey:@"userid"];
    [dict setObject:@"1" forKey:@"pageno"];
    [dict setObject:@"1" forKey:@"type"];
    [dict setObject:@"0" forKey:@"studentid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        [self->dataArray removeAllObjects];
        
        NSDictionary *dict = (NSDictionary *)resposeJson;
        NSArray * array = [dict objectForKey:@"re_data"];
        
        if (array.count == 0) {
            
            [self->emptyView showEmptyImage];
            [self->_tableView reloadData];
            [self->_tableView.mj_header endRefreshing];
            self->_tableView.tableFooterView = [[UIView alloc]init];
            
            return ;
        }else if(array.count == 20)
        {
            self->canFlipOver = YES;
            
        }else
        {
            self->canFlipOver = NO;
            
        }
        
        [self->emptyView hideEmptyImage];
        
        self->pageNum = 2;
        
        [self->dataArray addObjectsFromArray:array];
        [self.tableView.mj_header endRefreshing];
        [self.tableView reloadData];
        self->delegate.isChangeRole=@"no";
    } failure:^(NSInteger recode, NSError * error){
        
        if (error.code == -1009) {
            self->markLabel = 1;
            self.tableView.hidden = YES;
            [self ->noWifiView showEmptyImage];
        }
    }];
    
}
-(void)requestMoreSouceData
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_dynamic_liststudent" forKey:@"method"];
    [dict setObject:@"20" forKey:@"pagesize"];
    [dict setObject:USERID forKey:@"userid"];
    [dict setObject:@(pageNum) forKey:@"pageno"];
    [dict setObject:@"1" forKey:@"type"];
    [dict setObject:@"0" forKey:@"studentid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
//        [self->dataArray removeAllObjects];
        
        NSDictionary *dict = (NSDictionary *)resposeJson;
        NSArray * array = [dict objectForKey:@"re_data"];
        
        if (array.count == 20) {
            
            self->pageNum ++;
            
            self->canFlipOver = YES;
        }else
        {
            self->canFlipOver = NO;
        }
        
        [self->dataArray addObjectsFromArray:array];
        [self.tableView.mj_footer endRefreshing];
        [self.tableView reloadData];
        self->delegate.isChangeRole=@"no";
    } failure:^(NSInteger recode, NSError * error){
        
        if (error.code == -1009) {
            self->markLabel = 1;
            self.tableView.hidden = YES;
            [self ->noWifiView showEmptyImage];
        }
    }];
    
}
- (void)reloadCurrentData
{
    
    
    if (markLabel == 1) {
        [self ->noWifiView hideEmptyImage];
        self.tableView.hidden = NO;
        if ([lasttype isEqualToString:@"1"]) {
            
           [self requestDataForTableview];
            
        }else
        {
           [self requestSouceData];
        }
    }else
    {
        [self ->noPhotoWifiView hideEmptyImage];
        collect.hidden = NO;
        if ([lasttype isEqualToString:@"1"]) {
            
            [self requestTearchPhotosData];
            
        }else
        {
            [self requestParPhotosData];
        }
    }
    
}
#pragma mark -滚动视图的代理事件

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    
    //    [super scrollViewDidScroll:scrollView];
    [backView removeFromSuperview];//滑动 弹出条移除
    
    CGFloat sectionHeaderHeight = 210;
    
    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
        
        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
        
    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
        
        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)refreshFooterData{
    
    if (canFlipOver) {
        pageno ++;
        if ([lasttype isEqualToString:@"1"]) {
            [self requestDataForTableview];
        }else
        {
            [self requestSouceData];
        }
    }
    
    
}
- (void)refreshHeaderData{
    pageno=1;
    if ([lasttype isEqualToString:@"1"]) {
        [self requestDataForTableview];
    }else
    {
        [self requestSouceData];
    }
}

#pragma mark -导航条右侧按钮点击事件
-(void)dis:(id)sender{

    UIWindow *window=KeyWindow;
    DropDownMenu2 *table = [DropDownMenu2 shareDropDownMenu];
    NSArray * arr = @[@"发动态",@"我的收藏"];
    table.delegate = self;
    table.backViewFlag = 2;
    table.flag = YES;
    [table setDropDownMenuParameterWithcellContents:arr andWidth:120];
    [table hideDropDown:sender];
    [window addSubview:table];
}

#pragma mark -DropTableDelegate
- (void) niDropDownDelegateMethod:(DropDownMenu2 *) sender
{
    if (sender.senderTag == 0) {  //
        SendDynamicViewController *sendDynamicVC = [[SendDynamicViewController alloc] init];
        sendDynamicVC.delegate = self;
        sendDynamicVC.yddelegate = self;
        [self.navigationController pushViewController:sendDynamicVC animated:YES];
        
    }else if (sender.senderTag == 1) {
        
        ShouCangViewController *sCangVC=[[ShouCangViewController alloc]init];
        [self.navigationController pushViewController:sCangVC animated:YES];
    }
}
//- (void)tableViewCellSelected:(NSInteger)index{
//
//    if (index == 0) {  //跳转到考勤统计
//        SendDynamicViewController *sendDynamicVC = [[SendDynamicViewController alloc] init];
//        sendDynamicVC.delegate = self;
//        sendDynamicVC.yddelegate = self;
//        [self.navigationController pushViewController:sendDynamicVC animated:YES];
//
//    }else if (index == 1) {
//        ShouCangViewController *sCangVC=[[ShouCangViewController alloc]init];
//        [self.navigationController pushViewController:sCangVC animated:YES];
//    }
//}


#pragma mark - UITableviewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if(tableView == self.classPhontoTableView)
    {
    
        return 208;
        
    }else {
        
        NSString *flag=[NSString stringWithFormat:@"%@",[[dataArray objectAtIndex:indexPath.row] objectForKey:@"type"]];
        
        NSDictionary *dict = [dataArray objectAtIndex:indexPath.row];
        
        
        if ([flag isEqualToString:@"9"])
        {//系统消息 h5
            return 110;
        }else if([flag isEqualToString:@"1"])//普通消息
        {
            
            CGFloat imagesHeight;  //图片占有高度
            CGFloat comHeight; //回复view的高度
            CGFloat contentHeight;  //内容高度
            
            
            DFBaseLineItem *item = [DFBaseLineItem dictionaryWithDic:dict];
            
            if (!(item.praiseuser.count == 0 && item.replylist.count == 0)) {
                
                comHeight=[replayView getHeight:item maxWidth:SCREENWIDTH- 89];
            }
            
            NSString * fileidsStr = [dict objectForKey:@"fileid"];
            
            NSInteger line = 0;
            
            NSArray *fileids;
            
            if (fileidsStr.length != 0) {
                
                fileids = [fileidsStr componentsSeparatedByString:@","];
            }
            
            
            if ([fileids count]%3 == 0) {
                line = [fileids count]/3;
            }else
            {
                line = [fileids count]/3 + 1;
            }
            
            if (line > 0) {
                
                imagesHeight = 79 + (79 + 5) * (line - 1);
            }else{
                
                imagesHeight = -10;
            }
            
            contentHeight = [self resizeContenLabelHeightWithSting:[dict objectForKey:@"scontent"]];
//            contentHeight += 8  //加上边距
            
             return   36 + imagesHeight + contentHeight + comHeight + 32 + 8 + 15;
            

            
        }else{
            
            NSString * fileidsStr = [dict objectForKey:@"fileid"];
            
            NSInteger line = 0;
            
            
            NSArray *fileids;
            
            if (fileidsStr.length != 0) {
                
                fileids = [fileidsStr componentsSeparatedByString:@","];
            }
            
            
            if ([fileids count]%3 == 0) {
                line = [fileids count]/3;
            }else
            {
                line = [fileids count]/3 + 1;
            }
            
            return  (75 + 12.5) *line + [self resizeContenLabelHeightWithSting:[dict objectForKey:@"scontent"]] + 55 + 10 + 20;
        }
    }

}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if(tableView == self.classPhontoTableView)
    {
        photoListModel *model = [photosDataArray objectAtIndex:indexPath.row];
        ClassPhotoViewController *VC = [[ClassPhotoViewController alloc]init];
        VC.className = model.classname;
        VC.classid = model.classid;
        [self.navigationController pushViewController:VC animated:YES];
    
    }else
    {
        _keyboardState = NO;
        
        if (state == YES) {
            [self.backView removeFromSuperview];
            state = NO;
            return;
        }
    }
//    delegate = (AppDelegate *)CONSTAPPDELEGATE;
//    delegate.isChangeRole=@"no";//no  动态列表不刷新
//    NSString *flag=[NSString stringWithFormat:@"%@",[[dataArray objectAtIndex:indexPath.row] objectForKey:@"type"]];
//    if ([flag isEqualToString:@"8"]) {
//        FriendSysNoticeTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
//        
//        NSDictionary *dict = [dataArray objectAtIndex:indexPath.row];
//        
//        DetailDynViewController *detailVC = [[DetailDynViewController alloc] init];
//        detailVC.cell = cell;
//        detailVC.infoid=[dict objectForKey:@"infoid"];
//        detailVC.flag=@"tongzhi";
//        CGFloat height = [self tableView:tableView heightForRowAtIndexPath:indexPath];
//        
//        //第二个cell的高度
//        detailVC.cellHeight = height;
//        
//        [self.navigationController pushViewController:detailVC animated:YES];
//    }else if ([flag isEqualToString:@"9"])//h5
//    {
//        
//        WebViewController *web=[[WebViewController alloc]init];
//        web.controllerTitle=[[dataArray objectAtIndex:indexPath.row] objectForKey:@"urltitle"];
//        web.requestURL=[[dataArray objectAtIndex:indexPath.row] objectForKey:@"url"];
//        //判断有没有infologo
//        
//        NSString *infoLogoStr = [[dataArray objectAtIndex:indexPath.row] objectForKey:@"infologo"];
//        
//        if ([infoLogoStr isEqualToString:@"0"]) {
//            
//            if (![[[dataArray objectAtIndex:indexPath.row] objectForKey:@"logo"] hasPrefix:@"http"]) {
//                
//                web.logoImag = [NSString stringWithFormat:@"%@%@",REQUESTIMAGEURL,[[dataArray objectAtIndex:indexPath.row] objectForKey:@"logo"]];
//            }else
//            {
//                web.logoImag=[[dataArray objectAtIndex:indexPath.row] objectForKey:@"logo"];
//            }
//            
//        }else{
//            
//            web.logoImag=[NSString stringWithFormat:@"%@%@",PICPERFIXURL,[[dataArray objectAtIndex:indexPath.row] objectForKey:@"infologo"]];
//        }
//        web.flag=@"yes";
//        [self.navigationController pushViewController:web animated:YES];
//    }
    
}

#pragma mark - UITableviewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.classPhontoTableView) {
        
        NSLog(@"photosDataArray.count = %lu",(unsigned long)photosDataArray.count);
        
       return photosDataArray.count;
    
    }else
    {
       return [dataArray count];
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.classPhontoTableView) {
        
        photoListModel *model = [photosDataArray objectAtIndex:indexPath.row];
        
        SYClassPhotoCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SYClassPhotoCell"];
        if (cell == nil) {
            
            cell = [[[NSBundle mainBundle]loadNibNamed:@"SYClassPhotoCell" owner:nil options:nil] objectAtIndex:0];
        }
        
        cell.backView.layer.borderWidth = 0.5;
        cell.backView.layer.borderColor = [UIColor colorWithHexString:@"dedede"].CGColor;
        cell.backView.layer.cornerRadius = 5;
        cell.backView.clipsToBounds = YES;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [cell setDataForCellWith:model];
        
        return cell;
        
    }else
    {
    
    //flag=1 普通消息  8系统消息通知  9 h5页面显示
    NSString *flag=[NSString stringWithFormat:@"%@",[[dataArray objectAtIndex:indexPath.row] objectForKey:@"type"]];
    NSDictionary *dict;
    //取出字典
    dict = [dataArray objectAtIndex:indexPath.row];
    
    
    if ([flag isEqualToString:@"1"]) {  //普通消息
        
        classid = [dict objectForKey:@"classid"];
        
        FriendDynamicViewCell * cell = [tableView dequeueReusableCellWithIdentifier:dynamicIdentifier];
        if (cell == nil) {
            
            cell = [[FriendDynamicViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:dynamicIdentifier];
        }
        
        [cell.contentView addSubview:cell.headImage];
        cell.clickBtn.tag=indexPath.row+100;
        [cell.clickBtn addTarget:self action:@selector(clickTouchAction:) forControlEvents:UIControlEventTouchUpInside];
        
        
        [cell.praiseview removeFromSuperview];
        [cell upDateCellWithDic:dict];
        
        //头像
        NSString *imagePath = [dict objectForKey:@"logo"];
        
        if (![imagePath hasPrefix:@"http"]) {
            
            imagePath = [NSString stringWithFormat:@"%@%@",REQUESTIMAGEURL,imagePath];
        }
        
        [cell.headImage.headImage sd_setImageWithURL:[NSURL URLWithString:imagePath]];
        
        
        //头像昵称
        NSString *username = [dict objectForKey:@"username"];
        
        if (username.length > 2) {
            username = [username substringFromIndex:username.length-2];
        }
        //头像类型
        int logoType = [[dict objectForKey:@"logotype"] intValue];
        cell.headImage.flag = logoType == 1?YES:NO;
        cell.headImage.namelabel.font = [UIFont systemFontOfSize:14];
        cell.headImage.namelabel.text = username;
        
        //选择属性为无
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.likeCommentView.delegate = self;
        
        cell.likeCommentView.tag = indexPath.row + 1000;
        
        __weak typeof(self) weakSelf = self;
        __weak FriendDynamicViewCell *weakCell = cell;
        cell.headImage.tag = indexPath.row + 10000;
        cell.headImage.headPressed = ^(){
            
            [weakSelf headerTapAction:weakCell.headImage];
        };
        
        
        //删除按钮的点击事件
        cell.deleteBtn.tag = indexPath.row + 1000000;
        [cell.deleteBtn addTarget:self action:@selector(deleClick:) forControlEvents:UIControlEventTouchUpInside];
//        cell.selectionStyle = UITableViewCellSelectionStyleGray;
        return cell;
        
    }else if([flag isEqualToString:@"9"])
    {
        static NSString *identifier=@"syscell";
        FriendSysTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (cell == nil) {
            
            cell = [[FriendSysTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        
        [cell.contentView addSubview:cell.headImage];
        
        
        [cell upDateCellWithDic:dict];
        
        //头像
        NSString *imagePath = [dict objectForKey:@"logo"];
        
        if (![imagePath hasPrefix:@"http"]) {
            
            imagePath = [NSString stringWithFormat:@"%@%@",REQUESTIMAGEURL,imagePath];
        }
        
        //判断有没有infologo
        
        NSString *infoLogoStr = [dict objectForKey:@"infologo"];
        
        if ([infoLogoStr isEqualToString:@"0"]) {
            
            infoLogoStr = imagePath;
        }else{
            
            infoLogoStr = [NSString stringWithFormat:@"%@%@",PICPERFIXURL,infoLogoStr];
        }
        
        [cell.headImage sd_setImageWithURL:[NSURL URLWithString:imagePath]];
        
        [cell.logoImage sd_setImageWithURL:[NSURL URLWithString:infoLogoStr]];
        //选择属性为无
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
    }else
    {
        static NSString *sysNoticeIdentifier=@"sysNotice";
        FriendSysNoticeTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:sysNoticeIdentifier];
        if (cell == nil) {
            
            cell = [[FriendSysNoticeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sysNoticeIdentifier];
        }
        
        [cell.contentView addSubview:cell.headImage];
        
        
        [cell upDateCellWithDic:dict];
        
        //头像
        NSString *imagePath = [dict objectForKey:@"logo"];
        
        if (![imagePath hasPrefix:@"http"]) {
            
            imagePath = [NSString stringWithFormat:@"%@%@",REQUESTIMAGEURL,imagePath];
        }
        
        [cell.headImage.headImage sd_setImageWithURL:[NSURL URLWithString:imagePath]];
        
        //选择属性为无
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
        
      }
    }
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    if (tableView == self.classPhontoTableView) {
        
        if ( photoFlipOver == NO) {
            
            UIView *view =[[ UIView alloc] initWithFrame:CGRectMake(0, self.tableView.contentSize.height, VIEW_WIDTH, 60)];
            
            UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 0.4)];
            lineView.backgroundColor = RGBACOLOR(222, 223, 229, 1);
            
            UILabel *label=[[UILabel alloc]init];
            label.frame= CGRectMake(0, 0.4, VIEW_WIDTH, 59.6);
            
            label.text = @"没有更多内容了";
            label.font = [UIFont boldSystemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
            
            [label addSubview:lineView];
            
            [view addSubview:label];
            label.textColor = [UIColor colorWithHexString:@"979797"];
            self.classPhontoTableView.tableFooterView = view;
            self.classPhontoTableView.mj_footer = nil;
            
        }else if (photoFlipOver == YES){
            
            self.classPhontoTableView.tableFooterView = nil;
            
            self.classPhontoTableView.mj_footer =[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
                
                if ([self->lasttype isEqualToString:@"1"]) {
                    
                    [self requestTearchMorePhotosData];
                }else
                {
                    [self requestParMorePhotosData];
                }
            }];
        }

    }else
    {
        if (canFlipOver == NO) {
            
            UIView *view =[[ UIView alloc] initWithFrame:CGRectMake(0, self.tableView.contentSize.height, VIEW_WIDTH, 60)];
            
            UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 0.4)];
            lineView.backgroundColor = RGBACOLOR(222, 223, 229, 1);
            
            UILabel *label=[[UILabel alloc]init];
            label.frame= CGRectMake(0, 0.4, VIEW_WIDTH, 59.6);
            
            label.text = @"没有更多内容了";
            label.font = [UIFont boldSystemFontOfSize:14];
            label.textAlignment = NSTextAlignmentCenter;
            
            [label addSubview:lineView];
            
            [view addSubview:label];
            label.textColor = [UIColor colorWithHexString:@"979797"];
            self.tableView.tableFooterView = view;
            self.tableView.mj_footer = nil;
            
        }else if (canFlipOver == YES){
            
            self.tableView.tableFooterView = nil;
           
            self.tableView.mj_footer =[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
                
                 if ([self->lasttype isEqualToString:@"1"]) {
                     
                     [self requestMoreDataForTableview];
                 }else
                 {
                     [self requestMoreSouceData];
                 }
            }];
        }
    }
        //end of loading //for example [activityIndicator stopAnimating]; }}
}

#pragma mark -弹出条UI
-(void)clickTouchAction:(UIButton *)sender
{
    
    NSString *stateZan=[[dataArray objectAtIndex:sender.tag-100] objectForKey:@"ispraise"];//ispraise 点赞、取消状态值
    NSString *infoid=[[dataArray objectAtIndex:sender.tag-100] objectForKey:@"infoid"];//动态id
    FriendDynamicViewCell *cell=[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:sender.tag-100 inSection:0]];//获取当前点击cell
    
    self.replyViewDraw = [cell convertRect:cell.bounds toView:self.view.window].origin.y + cell.frame.size.height;
    
    
    [backView removeFromSuperview];
    backView=[[UIView alloc]initWithFrame:CGRectMake(sender.frame.origin.x- 145, sender.frame.origin.y - 22, 180, 30)];
    backView.centerY = sender.centerY - 9;
    backView.layer.cornerRadius=5;
    backView.backgroundColor= [UIColor colorWithHexString:@"#1ebfff"];
    [cell addSubview:backView];
    
    zanBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    zanBtn.frame=CGRectMake(0, 0, 60, 30);
    [zanBtn setImage:[UIImage imageNamed:@"dianzan_nor"] forState:UIControlStateNormal];
    [zanBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 6.5, 0, 0)];
    zanBtn.tag=[infoid intValue];
    if ([stateZan intValue]==0) {
        [zanBtn setTitle:@"点赞" forState:UIControlStateNormal];
        [zanBtn addTarget:self action:@selector(zanTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }else
    {
        [zanBtn setTitle:@"取消" forState:UIControlStateNormal];
        [zanBtn addTarget:self action:@selector(qxzanTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    zanBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    zanBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [zanBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,10.5,0,0)];
    
    [backView addSubview:zanBtn];
    
    UIView *line01=[[UIView alloc]initWithFrame:CGRectMake(60, 5, 0.5, 20)];
    line01.backgroundColor=[UIColor whiteColor];
    [backView addSubview:line01];
    
    pingBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    pingBtn.frame=CGRectMake(60, 0, 60, 30);
    pingBtn.tag=[infoid intValue];
    [pingBtn setImage:[UIImage imageNamed:@"pinglun_nor"] forState:UIControlStateNormal];
    [pingBtn setImageEdgeInsets:UIEdgeInsetsMake(0,-3,0,0)];
    
    [pingBtn setTitle:@"评论" forState:UIControlStateNormal];
    pingBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [pingBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,5.5,0,0)];
    [pingBtn addTarget:self action:@selector(pingTouchAction:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:pingBtn];
    
    UIView *line02=[[UIView alloc]initWithFrame:CGRectMake(120, 5, 0.5, 20)];
    line02.backgroundColor=[UIColor whiteColor];
    [backView addSubview:line02];
    
    cangBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    cangBtn.frame=CGRectMake(120, 0, 60, 30);
    cangBtn.tag=[infoid intValue];
    [cangBtn setImage:[UIImage imageNamed:@"shoucang_nor"] forState:UIControlStateNormal];
    [cangBtn setImageEdgeInsets:UIEdgeInsetsMake(0,-4.5,0,0)];
    [cangBtn setTitle:@"收藏" forState:UIControlStateNormal];
    cangBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [cangBtn setTitleEdgeInsets:UIEdgeInsetsMake(0,2.5,0,0)];
    [cangBtn addTarget:self action:@selector(cangAction:) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:cangBtn];
    
    state = YES;
}
//点赞响应事件
-(void)zanTouchAction:(UIButton *)sender
{
    [backView removeFromSuperview];
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_info_praiseadd" forKey:@"method"];
    [dict setObject:[NSString stringWithFormat:@"%ld",(long)sender.tag] forKey:@"infoid"];
    [dict setObject:USERID forKey:@"userid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        self->pageno=1;
        [self->dataArray removeAllObjects];
        if ([self->lasttype isEqualToString:@"1"]) {
            [self requestDataForTableview];
        }else
        {
            
            [self  requestSouceData ];
        }
        
    } failure:^(NSInteger recode, NSError * error){
        
    }];
}
//取消点赞响应事件
-(void)qxzanTouchAction:(UIButton *)sender
{
    [backView removeFromSuperview];
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_info_praisedel" forKey:@"method"];
    [dict setObject:[NSString stringWithFormat:@"%ld",(long)sender.tag] forKey:@"infoid"];
    [dict setObject:USERID forKey:@"userid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        self->pageno=1;
        [self->dataArray removeAllObjects];
        if ([self->lasttype isEqualToString:@"1"]) {
            [self requestDataForTableview];
        }else
        {
            [self  requestSouceData ];
        }
        
        
    } failure:^(NSInteger recode, NSError * error){
        
    }];
    
}

//评论按钮响应事件
-(void)pingTouchAction:(UIButton *)sender
{
    self.p_infoid=[NSString stringWithFormat:@"%ld",(long)sender.tag];
    [backView removeFromSuperview];
    [[UIApplication sharedApplication].keyWindow addSubview:_bottomView];
    
    _textView.text = @"";
    _textView.tag = 0;
    
    [_textView becomeFirstResponder];
    
    //_keyboardState = NO;
}
#pragma mark -注册键盘通知
-(void)configureKeyboardNoti{
    
    //    注册键盘消息通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboradWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
}
-(void)keyboradWillShow:(NSNotification *)note{
    
    NSDictionary *info = [note userInfo];
    CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;
    
    //if (keyBoardCount == 1 || keyBoardCount == 2) {
    //keyBoardCount++;
    //return;
    //}
    
    CGFloat offY = SCREENHEIGH - keyboardSize.height - _bottomView.frame.size.height;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    _bottomView.frame = CGRectMake(0, offY, VIEW_WIDTH, 50);
    
    //让tableView跟着评论框滑动
    CGPoint point = self.tableView.contentOffset;
    
    point.y -= (offY - self.replyViewDraw);
    self.tableView.contentOffset = point;
    
    [UIView commitAnimations];
    
    
}

-(void)keyboardWillHide:(NSNotification *)note{
    [_textView resignFirstResponder];
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    _bottomView.frame = CGRectMake(0, SCREENHEIGH+50, SCREENWIDTH, 50);
    [UIView commitAnimations];
}
#pragma mark -发送评论
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    
    if ([text isEqualToString:@"\n"]) {
        
        [_textView resignFirstResponder];
        long tag = _textView.tag;
        
        [self addPingLunandTag:tag];
        
        return NO;
    }
    return YES;
}
//添加评论接口
-(void)addPingLunandTag:(long)tag
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_info_replyadd" forKey:@"method"];
    [dict setObject:self.p_infoid forKey:@"infoid"];
    [dict setObject:USERID forKey:@"userid"];
    
    NSString *toUserStr = [NSString stringWithFormat:@"%ld",tag];
    
    if (tag > 0) {  //大于0表示
        
        [dict setObject:toUserStr forKey:@"touserid"];
    }
    
    [dict setObject:_textView.text forKey:@"scontent"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        self->pageno=1;
        [self->dataArray removeAllObjects];
        if ([self->lasttype isEqualToString:@"1"]) {
            [self requestDataForTableview];
        }else
        {
            [self  requestSouceData ];
        }
        
        
    } failure:^(NSInteger recode, NSError * error){
        
    }];
    
}

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    
    return YES;
}

-(void)textViewDidBeginEditing:(UITextView *)textView{
    
    //    if([textView.text isEqualToString:@"点此输入评论"]){
    
    
    textView.textColor=[UIColor blackColor];
    //    }
    
}

-(void)textViewDidChange:(UITextView *)textView{
    
    if ([textView.text hasPrefix:@"回复"]) {
        textView.text=@"";
    }
    
    textView.textColor=[UIColor blackColor];
}


-(BOOL)textViewShouldEndEditing:(UITextView *)textView{
    
    [_textView resignFirstResponder];
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    _bottomView.frame = CGRectMake(0, SCREENHEIGH-50, SCREENWIDTH, 50);
    [UIView commitAnimations];
    
    return YES;
    
}

#pragma mark -删除动态
-(void)deleClick:(UIButton *)sender{
    
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"删除" otherButtonTitles: nil];
    sheet.tag = sender.tag;
    [sheet showInView:self.view];
}

#pragma mark -收藏
-(void)cangAction:(UIButton *)sender
{
    [backView removeFromSuperview];
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dict setObject:@"api_info_collectionadd" forKey:@"method"];
    [dict setObject:[NSString stringWithFormat:@"%ld",(long)sender.tag] forKey:@"infoid"];
    [dict setObject:USERID forKey:@"userid"];
    
    [Utils noIndiGet:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        
        [self shouCangAlert];
    } failure:^(NSInteger recode, NSError * error){
        
        
    }];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    if (tableView == self.classPhontoTableView) {
        
        return nil;
        
    }else
    {
    
    UIView *headerView = [[UIView alloc] init];
    headerView.frame = CGRectMake(0, 0, SCREENWIDTH, 180);
    
    bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 160)];
    
    //bgImageView.backgroundColor = [UIColor cyanColor];
    bgImageView.contentMode = UIViewContentModeScaleAspectFill;
    bgImageView.clipsToBounds = YES;
    bgImageView.userInteractionEnabled = YES;
    
    [bgImageView sd_setImageWithURL:[NSURL URLWithString:bgImageUrl] placeholderImage:[UIImage imageNamed:@"m_top_img"]];
    
    UILabel *nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 136, [UIScreen mainScreen].bounds.size.width - 91, 17)];
    nameLabel.textAlignment=NSTextAlignmentRight;
    nameLabel.text=accountDic.username;
    nameLabel.font=[UIFont boldSystemFontOfSize:16];
    nameLabel.textColor=[UIColor whiteColor];
    nameLabel.shadowOffset = CGSizeMake(1, 1);
    nameLabel.shadowColor = RGBACOLOR(0, 0, 0, 0.3);
        
    
    
    headImageView = [[XZHeaderImageView alloc] initWithFrame:CGRectMake(SCREENWIDTH - 80, 130, 60, 60)];
    
    headUrl = [[NSUserDefaults standardUserDefaults] objectForKey:XZHEADURL];

    
    if (!headUrl) {
        headUrl = accountDic.logo;
    }
    
    if (![headUrl hasPrefix:@"http"]) {
        headUrl = [REQUESTIMAGEURL stringByAppendingString:headUrl];
    }
    
    [headImageView.headImage sd_setImageWithURL:[NSURL URLWithString:headUrl]];
    
    headImageView.clipsToBounds = YES;
    headImageView.layer.cornerRadius = 30;
    headImageView.userInteractionEnabled = YES;
    headImageView.contentMode = UIViewContentModeScaleAspectFill;
    
    
    //更换背景图片的手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeBGImage:)];
    tap.numberOfTapsRequired = 1;
    tap.numberOfTouchesRequired = 1;
    [bgImageView addGestureRecognizer:tap];
    
    //点击进入个人中心的手势
    //    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toUserDynamicVc:)];
    //    tap.numberOfTapsRequired = 1;
    //    tap.numberOfTouchesRequired = 1;
    //[headImageView addGestureRecognizer:tap2];
    
    __block SYNewDynamicViewController *blockSelf = self;
    
    headImageView.headPressed = ^(){
        
        [blockSelf toUserDynamicVc];
    };
    
    [headerView addSubview:bgImageView];
    [headerView addSubview:headImageView];
    [headerView addSubview:nameLabel];
    
    
    return headerView;
    }
}
////获取头像上的名称
//-(NSString *)getNameOfImage:(NSString *)UserID
//{
//    NSDictionary *nameofimg=[[NSUserDefaults standardUserDefaults]objectForKey:@"user_nameOfImage"];
//    NSString *name;
//    if ([nameofimg.allKeys count]>0) {
//        for (int h=0; h<[nameofimg.allKeys count];h++) {
//            if ([UserID isEqualToString:[nameofimg.allKeys objectAtIndex:h]]) {
//                name=[nameofimg objectForKey:UserID];
//                nickLabel.hidden=NO;
//                nickLabel.text=name;
//            }
//        }
//    }else
//    {
//        nickLabel.hidden=YES;
//    }
//    
//    return  name;
//}
#pragma mark -加载个人信息
-(void)getUserInfoWithUserid:(NSString *)userid{
    
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    
    [dict setObject:@"api_user_getinfobyid" forKey:@"method"];
    
    [dict setObject:userid forKey:@"userid"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        [self hideHud];
        
        NSDictionary *redataDic = [resposeJson objectForKey:@"re_data"];
        if (redataDic.count>0) {
            NSDictionary *userinfoDic = [redataDic objectForKey:@"userinfo"];
            
            self->bgImageUrl = [[userinfoDic objectForKey:@"basepic"] stringValue];
            
           
            
            if ([self->bgImageUrl isEqualToString:@"0"]) {
                self->bgImageUrl = @"https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1458264274&di=75597c9973c5572952d28f9f880defd2&src=http://file25.mafengwo.net/M00/00/84/wKgB4lYvUmeAWxYLAAu-KKvEhO037.jpeg";
            }else{
                
                //正式环境
                self->bgImageUrl = [NSString stringWithFormat:@"%@%@",IMAGEHOSTURL,self->bgImageUrl];
            }
            self->headUrl = [userinfoDic objectForKey:@"logo"];
            
            if (![self->headUrl hasPrefix:@"http"]) {
                self->headUrl = [NSString stringWithFormat:@"%@%@",REQUESTIMAGEURL,self->headUrl];
            }
            self->nickName=[userinfoDic objectForKey:@"username"];
            
            self->nickName2=[userinfoDic objectForKey:@"username"];
            
            self->hLogoType=[[userinfoDic objectForKey:@"logotype"] intValue];
            
        }
        [self.tableView reloadData];
        
    } failure:^(NSInteger recode, NSError * error){
        
        
    }];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    if(tableView == self.classPhontoTableView)
    {
        return 0;
    }else
    {
        return 190;
    }
}

#pragma mark -改变背景图片的手势
-(void)changeBGImage:(UIGestureRecognizer *)tap{
    
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"照相机",@"相册", nil];
    sheet.tag = 1;
    [sheet showInView:self.view];
}
-(void)toUserDynamicVc{
    UserDynamicViewController *userdynameVc=[[UserDynamicViewController alloc]init];
    userdynameVc.headUrl= headUrl;
    userdynameVc.userid = USERID;
    userdynameVc.LogoType= accountDic.logotype;
    userdynameVc.nickName= accountDic.username;
    [self.navigationController pushViewController:userdynameVc animated:YES];
    
}

-(void)headerTapAction:(UIView *)tap{
    
    long tag = tap.tag - 10000;
    
    NSDictionary *dic = [dataArray objectAtIndex:tag];
    
    NSString *userid = [[dic objectForKey:@"userid"] stringValue];
    
    UserDynamicViewController *userdynameVc=[[UserDynamicViewController alloc]init];
    userdynameVc.userid = userid;
    userdynameVc.nickName= [dic objectForKey:@"username"];
    
    [self.navigationController pushViewController:userdynameVc animated:YES];
    
}

#pragma mark -UIActionsheetDelegate
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (actionSheet.tag != 1) {  //评论
        
        if (buttonIndex == 1) {  //取消
            
        }else{  //删除回复
            
            if (actionSheet.tag >= 1000000) {
                
                //                NSDictionary * imformation = [Utils acquirePersonalImformationFromMemoryWithPersonID:USERID];
                //                NSDictionary *userInfo = [imformation objectForKey:@"userinfo"];
                //                lasttype = [[userInfo objectForKey:@"lasttype"] stringValue];
                
                NSString *infoid=[[[dataArray objectAtIndex:actionSheet.tag-1000000] objectForKey:@"infoid"] stringValue];//动态id
                classid =[[dataArray objectAtIndex:actionSheet.tag-1000000] objectForKey:@"classid"];//动态id
                
                NSString *studentId;
                NSString *userid = USERID; //
                
                if ([lasttype isEqualToString:@"1"]) {
                    
                    studentId = @"0";
                }else{
                    studentId = self -> childID;
                }
                
                NSMutableDictionary *param = [NSMutableDictionary dictionary];
                
                [param setObject:@"api_info_delete" forKey:@"Method"];
                [param setObject:infoid forKey:@"infoid"];
                [param setObject:classid forKey:@"classid"];
                [param setObject:studentId forKey:@"studentid"];
                [param setObject:userid forKey:@"userid"];
                
                [Utils get:nil parameters:param success:^(NSInteger recode, id jsonObject) {
                    
                    self->pageno=1;
                    [self->dataArray removeAllObjects];
                    if ([self->lasttype isEqualToString:@"1"]) {
                        [self requestDataForTableview];
                    }else
                    {
                        [self  requestSouceData ];
                    }
                    
                    
                } failure:^(NSInteger recode, NSError *error) {
                    
                }];
                
                return;
            }else{
                
                NSString * tag = [NSString stringWithFormat:@"%ld",(long)actionSheet.tag];
                
                NSMutableDictionary *param = [NSMutableDictionary dictionary];
                
                [param setObject:@"api_info_replydel" forKey:@"Method"];
                [param setObject:tag forKey:@"replyid"];
                
                [Utils get:nil parameters:param success:^(NSInteger recode, id jsonObject) {
                    
                    self->pageno=1;
                    [self->dataArray removeAllObjects];
                    if ([self->lasttype isEqualToString:@"1"]) {
                        [self requestDataForTableview];
                    }else
                    {
                        [self  requestSouceData ];
                    }
                    
                    
                } failure:^(NSInteger recode, NSError *error) {
                    
                }];
            }
        }
        
        return;
    }
    
    if (buttonIndex == 2) { //取消
        return;
    }
    
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.delegate = self;
    
    imagePicker.allowsEditing = YES;
    
    if (buttonIndex == 0) {  //照相机
        NSString *mediaType = AVMediaTypeVideo;
        
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
        
        
        if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){
            
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的“设置－隐私－相机”中允许访问相机" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            alert.tag=201;
            [alert show];
            
        }else
        {
            imagePicker.mediaTypes = [[NSArray alloc] initWithObjects:(__bridge NSString *)kUTTypeImage, nil];
            
            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:imagePicker animated:YES completion:nil];
        }
        
    }else{   //图库
        
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
    
    
}

#pragma mark -图片选择完成的回调
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    
    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
    
    chooseImage = [info objectForKey:UIImagePickerControllerEditedImage];
    
    UIImageOrientation imageOrientation = chooseImage.imageOrientation;
    
    if (imageOrientation != UIImageOrientationUp) {
        
        UIGraphicsBeginImageContext(chooseImage.size);
        [chooseImage drawInRect:CGRectMake(0, 0, chooseImage.size.width, chooseImage.size.height)];
        chooseImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
    
    [picker dismissViewControllerAnimated:YES completion:^{
        if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage])
        {
            
            
            
            NSData * fileData = UIImageJPEGRepresentation(self->chooseImage, 0.5);
            
            NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
            [dict setObject:@"InsertfileInfo" forKey:@"method"];
            [dict setObject:@"1" forKey:@"typeid"];
            [dict setObject:[fileData base64Encoding] forKey:@"file"];
            [dict setObject:@"11" forKey:@"filename"];
            [dict setObject:@"file" forKey:@"description"];
            [dict setObject:@".jpg" forKey:@"kz"];
            dict  = [Utils completeImageSubmitParameterWith:dict];
            NSString * postValue = [Utils getXMLStringWithParameter:dict];
            
            __weak typeof(self) weakSelf = self;
            
            self ->bgImageView.image = self->chooseImage;
            [Utils submitImageToWebService:SUBMITIMAGEURL SOAPActionSring:@"http://tempuri.org/InsertfileInfo" postValue:postValue success:^(NSInteger recode, id resposeJson)
             {
                 
                 
                 NSDictionary * dict = (NSDictionary *)resposeJson;
                 NSString * returncode = [dict objectForKey:@"returncode"];
                 if ([returncode isEqualToString:@"10000"])
                 {
                     NSString * url = [dict objectForKey:@"url"];
                     
                     url=[NSString stringWithFormat:@"%@%@",REQUESTIMAGEURL,url];
                     self->bgImageUrl=url;

                     NSString *imageId = [resposeJson objectForKey:@"id"];
                     
                     [Utils resaePersonadataWithBacePic:imageId];
                     
                     [self upLoadImageWithUrl:imageId];
                     [weakSelf hideHud];
                     
                     
                 }
                 
                 
             } failure:^(NSInteger recode, NSError * error)
             {
                 [self hideHud];
                 [self showHint:NSLocalizedString(@"setting.uploadFail", @"uploaded failed")];
             }];
            
        }
    }];
    
}
//123
-(void)upLoadImageWithUrl:(NSString *)uploadImage{
    
    if (uploadImage.length == 0) {
        
        return;
    }
    
    NSMutableDictionary * dict = [[NSMutableDictionary alloc] initWithCapacity:0];
    
    [dict setObject:@"api_add_basepic" forKey:@"method"];
    
    [dict setObject:USERID forKey:@"userid"];
    
    [dict setObject:uploadImage forKey:@"basepic"];
    
    [Utils get:nil parameters:dict success:^(NSInteger recode, id resposeJson){
        [self hideHud];
        [self showHint:@"背景图片修改成功"];
        
        
    } failure:^(NSInteger recode, NSError * error){
        
    }];
    
}

#pragma mark -- other
- (CGFloat)resizeContenLabelHeightWithSting:(NSString *)text
{
    if (text.length == 0) {
        return 0;
    }
    UIFont *font = [UIFont systemFontOfSize:14];
    
    NSStringDrawingOptions opts = NSStringDrawingUsesLineFragmentOrigin/* |
                                                                        NSStringDrawingUsesFontLeading*/;
    
    //NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    //[style setLineBreakMode:NSLineBreakByCharWrapping];
    
    NSDictionary *attributes = @{ NSFontAttributeName : font/*, NSParagraphStyleAttributeName : style*/ };
    
    CGSize maxSize = CGSizeMake(SCREENWIDTH - 11 - 64, CGFLOAT_MAX);
    CGSize size = [text boundingRectWithSize:maxSize
                                     options:opts
                                  attributes:attributes
                                     context:nil].size;
    return size.height;
}


#pragma mark -disViewdelegate
-(void)reloadTableViewData{
    
    [self refreshHeaderData];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    
    if (alertView.tag==101) {
        
        if (buttonIndex == 1) return;  //取消
        
        UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier:@"StudentViewController"];
        
        [self.navigationController pushViewController:vc animated:YES];
        return;
    }else if (alertView.tag==201)
    {
        return;
    }
    else
    {
        if (buttonIndex == 0) return;
        UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier:@"BoundPhoneViewController"];
        
        [self.navigationController pushViewController:vc animated:YES];
    }
    
}
-(void)loadParentStudentList
{
    NSUserDefaults *ud=[NSUserDefaults standardUserDefaults];
    NSString *studentID=[ud objectForKey:@"studentID"];
    if (studentID!=nil) {
        childID=studentID;
        [emptyView hideEmptyImage];

        [self requestSouceData];
    }else
    {
        
        [emptyView showEmptyImage];

    }
    
}

-(void)onclikerUser:(NSUInteger)userId{
    
    UserDynamicViewController *userdynameVc=[[UserDynamicViewController alloc]init];
    userdynameVc.userid = [NSString stringWithFormat:@"%ld",(long)userId];
    [self.navigationController pushViewController:userdynameVc animated:YES];
}


-(void)onclikerComment:(NSString *)commentId andUserid:(NSString *)userid andTag:(int)tag andReplayid:(NSInteger)replayid{
    
    if ([userid isEqualToString:USERID]) {
        
        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"删除" otherButtonTitles:nil];
        [sheet showInView:self.view];
        sheet.tag = replayid;
        return;
    }
    
    tag = tag - 1000;
    
    self.p_infoid =[[dataArray objectAtIndex:tag] objectForKey:@"infoid"];
    
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:tag inSection:0];
    
    FriendDynamicViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    
    self.replyViewDraw = [cell convertRect:cell.bounds toView:self.view.window].origin.y + cell.frame.size.height;
    
    [backView removeFromSuperview];
    [[UIApplication sharedApplication].keyWindow addSubview:_bottomView];
    
    _textView.text = [NSString stringWithFormat:@"回复%@ : ",commentId];
    
    _textView.textColor = [UIColor lightGrayColor];
    
    _textView.delegate = self;
    
    _textView.tag = [userid integerValue];
    
    [_textView becomeFirstResponder];
    
}
-(void)shouCangAlert
{
    control=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGH)];
    control.backgroundColor=[UIColor clearColor];
    
    img=[[UIImageView alloc]initWithFrame:CGRectMake((SCREENWIDTH-120)/2, ( SCREENHEIGH-120)/2, 120, 120)];
    img.image=[UIImage imageNamed:@"shoucang_"];
    [control addSubview:img];
    
    UIWindow *window=KeyWindow;
    [window addSubview:control];
    
    [self performSelector:@selector(cancelAction) withObject:nil afterDelay:1];
    
}
-(void)cancelAction
{
    [control removeFromSuperview];
}

-(void)showYunDouAlert:(NSString *)string andNum:(int)num
{
    
    CustomAlert *alert=[CustomAlert ShareCustomAlert];
    [alert showAlertTaskString:string andNum:num];
}


@end
